const mongoose = require('mongoose')

const messageSchema = new mongoose.Schema({
  fromUser: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: [true, '请提交发送用户id']
  },
  toUser: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: [true, '请提交接收用户id']
  },
  // 发送内容
  content: {
    type: String,
    required: true
  },
  // 创建时间(时间戳)
  createTime: {
    type: Number,
    required: true
  },
  // 消息是否已读
  isRead: {
    type: Boolean,
    default: false
  }
})

// 根据规则创建集合
const Message = mongoose.model('Message', messageSchema)

// 将集合规则作为模块成员进行导出
module.exports = {
  Message
}